package com.heima.app;

import com.heima.Config.SpringConfig;
import com.heima.Dao.BookDao;
import com.heima.Service.BookService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

import javax.sql.DataSource;
import java.sql.SQLException;

public class AnnApp {
    public static void main(String[] args) throws SQLException {
        //1.解析配置类，获取容器
        AnnotationConfigApplicationContext app =
                new AnnotationConfigApplicationContext(SpringConfig.class);

        /*//2.获取bean 使用
        BookDao bookDaoImpl = (BookDao) app.getBean("bookDaoImpl");
        bookDaoImpl.save();*/

        /*BookService bean = app.getBean(BookService.class);
        bean.save();*/

        //DataSource dataSource = app.getBean(DataSource.class);
        DataSource dataSource = (DataSource) app.getBean("dataSource");

        System.out.println(dataSource.getConnection().isClosed());

        app.close();
    }
}
